package com.androidhive.androidlistview;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class VendorMenu extends ListActivity {
	SessionManager session;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        session = new SessionManager(getApplicationContext());
        
        // storing string resources into Array
        String[] vendor_menu = getResources().getStringArray(R.array.vendor_menu);
        
        // Binding Array to ListAdapter
        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, vendor_menu));
        
        ListView lv = getListView();

        // listening to single list item on click
        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
        	  
        	  // selected item 
        	  String product = ((TextView) view).getText().toString();
        	  if(product.equalsIgnoreCase("Logout")){
        		  session.logoutUser();
        	  // Launching new Activity on selecting single List Item
        	  Intent i = new Intent(getApplicationContext(), AppEntrance.class);
        	  // sending data to new activity
        	  i.putExtra("product", product+"rk");
        	  startActivity(i);
        	
          }
        	  if(product.equalsIgnoreCase("View All crops")){
            	 //  Launching new Activity on selecting single List Item
            	  Intent i = new Intent(getApplicationContext(), ListViewCheckboxesActivity.class);
            	  // sending data to new activity
            	  i.putExtra("product", product+"rk");
            	  startActivity(i);
            	
              }  
        	  if(product.equalsIgnoreCase("Search Crop by Name")){
             	 //  Launching new Activity on selecting single List Item
             	  Intent i = new Intent(getApplicationContext(), SingleListItem.class);
             	  // sending data to new activity
             	//  i.putExtra("product", product+"rk");
             	  startActivity(i);
             	
               }  
        	  if(product.equalsIgnoreCase("Search Crop by State")){
              	 //  Launching new Activity on selecting single List Item
              	  Intent i = new Intent(getApplicationContext(), StateWiseSearch.class);
              	  // sending data to new activity
              	//  i.putExtra("product", product+"rk");
              	  startActivity(i);
              	
                }  
        	  if(product.equalsIgnoreCase("View Profile")){
              	 //  Launching new Activity on selecting single List Item
              	  Intent i = new Intent(getApplicationContext(),VViewProfile.class);
              	  // sending data to new activity
              	//  i.putExtra("product", product+"rk");
              	  startActivity(i);
              	
                }  
          
          
          }
        });
    }
}